home *** CD-ROM | disk | FTP | other *** search
- /* Boolean.c
- This code demonstrates Boolean gadgets.
-
- Patrick Hager, Great Valley Products Inc.
- November 2, 1993
- */
-
-
- #include <stdio.h>
- #include "/global/userwindow.h"
- #include "/global/egslibraries.h"
-
- #include <egs/egsintui.h>
- #include <egs/clib/egsintui_protos.h>
- #include <egs/pragmas/egsintui_pragmas.h>
- #include <egs/egsgadbox.h>
- #include <egs/clib/egsgadbox_protos.h>
- #include <egs/pragmas/egsgadbox_pragmas.h>
-
-
-
-
- #define SIMPLE_ID 100 // Gadget ID base for three Simple Booleans.
-
-
- /* Used with Simple Mode.
- If (Simple_Mode & LEFT_SIMPLE_FLAG) it means this
- button is pushed in. This is just my way of
- doing it. You must remember your button
- positions somehow, so you can correctly
- redraw them on a reopen, or a resize.
- */
- #define LEFT_SIMPLE_FLAG 1
- #define MIDDLE_SIMPLE_FLAG 2
- #define RIGHT_SIMPLE_FLAG 4
-
- #define EXCLUDE_ID 200 // Gadget ID Base for 5 Mutually Excluded Booleans.
- #define NUM_EXCLUDE_GADGETS 5 // Number of Mutually Excluded Gadgets (5)
-
-
- // Our UserInputWindow structure.
- struct UserInputWindow Example_Request;
-
- // This is necessary to have mutually excluded
- // boolean gadgets. Allocate to one more than
- // the number of gadgets, and fill last one
- // with NULL.
- EI_BoolGadPtr Exclude_List[NUM_EXCLUDE_GADGETS+1];
-
- // Shows me which Mutually Excludeded Boolean is
- // is pressed in. (0-4)
- WORD Mutual_Mode=0;
- UWORD Simple_Mode=0; // See above. LEFT_SIMPLE_FLAG etc.
-
-
-
- // Local PRIVATE function Prototypes.
-
- EB_GadBoxPtr Create_Example (UserInputWindowPtr UserWindow);
- void GadgetDown_Example (UserInputWindowPtr UserWindow, EI_GadgetPtr iaddress);
- void Redraw_Example (UserInputWindowPtr UserWindow);
-
-
- /****************************
- MAIN CODE
- ****************************/
- void main (void) {
-
- if (OpenEGSLibraries ()) {
- Init_UserWindow (&Example_Request, "Boolean Example Window",WINDOW_MODAL,
- NULL,NULL);
- Example_Request.Create = Create_Example;
- Example_Request.GadgetDown = GadgetDown_Example;
- Example_Request.Redraw = Redraw_Example; // We need redraw to update
- // on resize or reopen.
- Example_Request.IDCMPFlags = EI_iCLOSEWINDOW | EI_iSIZEVERIFY |
- EI_iNEWSIZE | EI_iGADGETDOWN;
- Example_Request.Flags = EI_SIZEBBOTTOM| EI_SIMPLE_REFRESH |
- EI_GIMMEZEROZERO;
- Example_Request.SysGadgets = (EI_WINDOWCLOSE)|(EI_WINDOWSIZE)|EI_WINDOWDRAG|
- EI_WINDOWFRONT|EI_WINDOWBACK;
-
- if (Open_UserWindow (&Example_Request,-1,-1)) {
- Close_UserWindow (&Example_Request);
- }
- else
- printf ("Couldn't open my window!\n");
-
- }
- CloseEGSLibraries (); // after the bracket cause what if I opened 3 but
- // couldn't find the rest, still need to close the 3.
- }
-
- /*************************************
- PRIVATE: Create_Example.
- This routine is called by the UserWindow routines.
- It passes back a GadBoxPtr to the gadgets wanted.
- *************************************/
- EB_GadBoxPtr Create_Example (UserInputWindowPtr UserWindow) {
- EB_GadBoxPtr root, horiz, box;
- EB_GadContext gadcon;
-
- gadcon = UserWindow->GadCon;
-
- root = EB_CreateVertiBox (gadcon);
- EB_AddLastSon (root,EB_CreateVertiFill (gadcon,0,0));
- EB_AddLastSon (root,EB_CreateCenterText (gadcon,"Note we remember positions "
- "on resize..."));
-
- /* For the Simple Booleans along the top, I just check the
- Simple_Mode variable as I create the gadgets. If this
- particular gadget needs to be pressed in, set the Flag
- to one. You can look up these structures in egsgadbox.h.
- */
- EB_AddLastSon (root,EB_CreateVertiFill (gadcon,0,0));
- horiz=EB_CreateHorizBox (gadcon);
- box=EB_CreateTextBoolean (gadcon,"Simple Boolean 1",SIMPLE_ID+0,EB_FILL_ALL);
- if (Simple_Mode & LEFT_SIMPLE_FLAG)
- ((EI_BoolGadPtr)box->Render.Gad)->Flag=1;
- EB_AddLastSon (horiz,box);
- box=EB_CreateTextBoolean (gadcon,"Simple Boolean 2",SIMPLE_ID+1,EB_FILL_ALL);
- if (Simple_Mode & MIDDLE_SIMPLE_FLAG)
- ((EI_BoolGadPtr)box->Render.Gad)->Flag=1;
- EB_AddLastSon (horiz,box);
- box=EB_CreateTextBoolean (gadcon,"Simple Boolean 3",SIMPLE_ID+2,EB_FILL_ALL);
- if (Simple_Mode & RIGHT_SIMPLE_FLAG)
- ((EI_BoolGadPtr)box->Render.Gad)->Flag=1;
- EB_AddLastSon (horiz,box);
- EB_AddLastSon (root,horiz);
-
- /* For the Five Mutually Excluded Gadgets along the bottom,
- I need to do a couple things.
- First. UnSet the EI_TOGGLE_SELECT Flag. This keeps the
- gadget from being toggled from one state to another.
- if its pushed in, you can't push it out.
- Second. Set its Exclude struct to our List we allocated at
- runtime. This tells EGS which ones to pop out if
- this gadget is pressed in.
- Third. Add to the list with this gadget. (The list wouldn't
- do EGS much good unless it contained the gadget's
- addresses.) Set the Last Entry to NULL.
- */
- horiz=EB_CreateHorizBox (gadcon);
- box=EB_CreateTextBoolean (gadcon,"Exclude Boolean 1",EXCLUDE_ID+0,EB_FILL_ALL);
- ((EI_BoolGadPtr)box->Render.Gad)->Class.Flags &= (~EI_TOGGLE_SELECT);
- ((EI_BoolGadPtr)box->Render.Gad)->Exclude=(struct EI_BoolGadget **) &Exclude_List;
- Exclude_List[0]=(EI_BoolGadPtr)box->Render.Gad;
- EB_AddLastSon (horiz,box);
- box=EB_CreateTextBoolean (gadcon,"Exclude Boolean 2",EXCLUDE_ID+1,EB_FILL_ALL);
- ((EI_BoolGadPtr)box->Render.Gad)->Class.Flags &= (~EI_TOGGLE_SELECT);
- ((EI_BoolGadPtr)box->Render.Gad)->Exclude=(struct EI_BoolGadget **) &Exclude_List;
- Exclude_List[1]=(EI_BoolGadPtr)box->Render.Gad;
- EB_AddLastSon (horiz,box);
- box=EB_CreateTextBoolean (gadcon,"Exclude Boolean 3",EXCLUDE_ID+2,EB_FILL_ALL);
- ((EI_BoolGadPtr)box->Render.Gad)->Class.Flags &= (~EI_TOGGLE_SELECT);
- ((EI_BoolGadPtr)box->Render.Gad)->Exclude=(struct EI_BoolGadget **) &Exclude_List;
- Exclude_List[2]=(EI_BoolGadPtr)box->Render.Gad;
- EB_AddLastSon (horiz,box);
- box=EB_CreateTextBoolean (gadcon,"Exclude Boolean 4",EXCLUDE_ID+3,EB_FILL_ALL);
- ((EI_BoolGadPtr)box->Render.Gad)->Class.Flags &= (~EI_TOGGLE_SELECT);
- ((EI_BoolGadPtr)box->Render.Gad)->Exclude=(struct EI_BoolGadget **) &Exclude_List;
- Exclude_List[3]=(EI_BoolGadPtr)box->Render.Gad;
- EB_AddLastSon (horiz,box);
- box=EB_CreateTextBoolean (gadcon,"Exclude Boolean 5",EXCLUDE_ID+4,EB_FILL_ALL);
- ((EI_BoolGadPtr)box->Render.Gad)->Class.Flags &= (~EI_TOGGLE_SELECT);
- ((EI_BoolGadPtr)box->Render.Gad)->Exclude=(struct EI_BoolGadget **) &Exclude_List;
- Exclude_List[4]=(EI_BoolGadPtr)box->Render.Gad;
- Exclude_List[5]= NULL;
- EB_AddLastSon (horiz,box);
- EB_AddLastSon (root,horiz);
-
- return root;
- }
-
- /**************************************
- PRIVATE: GadgetDown_Example.
- This routine handles the gadget down events passed to the
- Example Control Window.
- **************************************/
- void GadgetDown_Example (UserInputWindowPtr UserWindow, EI_GadgetPtr iaddress) {
-
- // Process our mutually Excluded Bool Gadgets.
-
- if ((iaddress->GadgetID >= EXCLUDE_ID)&&
- (iaddress->GadgetID < EXCLUDE_ID+NUM_EXCLUDE_GADGETS)) {
- // Sets our mode to 0-4.
- Mutual_Mode = iaddress->GadgetID-EXCLUDE_ID;
- }
- else switch (iaddress->GadgetID) {
-
- //If it was pushed in,... pop it out and vice versa
- // (^ = Exclusive Or.)
- case SIMPLE_ID: Simple_Mode ^= LEFT_SIMPLE_FLAG; break;
- case SIMPLE_ID+1: Simple_Mode ^= MIDDLE_SIMPLE_FLAG; break;
- case SIMPLE_ID+2: Simple_Mode ^= RIGHT_SIMPLE_FLAG; break;
- }
- }
-
- /**************************************
- PUBLIC: Redraw_Example.
- This routine handles redraw events to the Example
- Control Window. Called by UserWindow routines, and
- could be called by other routines as well.
- Also called on an EI_iREFRESHWINDOW message.
- **************************************/
- void Redraw_Example (UserInputWindowPtr UserWindow) {
- int i;
-
- /* Assume we are starting out with a fresh set of gadgets,
- (from a resize, or a reopen), and set the appropriate
- Mutual Boolean gadget's flag to True.
- Then refresh all of the mutual exclude gadgets.
- */
-
- Exclude_List[Mutual_Mode]->Flag=TRUE;
- for (i=0;i<NUM_EXCLUDE_GADGETS;i++) {
- EI_RefreshGadget (UserWindow->Window,(EI_GadgetPtr)Exclude_List[i]);
- }
-
- /* There is no need to refresh the Simple gadgets along the top,
- because they were set accordingly in the Create routine.
- */
- }
-